namespace Pdf
{
	Splitter::Inserter::Inserter(OutputDocument *document, Splitter *splitter) 
		: document(document), splitter(splitter)
	{    }

	void Splitter::Inserter::visited(Array *obj)
	{
		for (Array::Iterator i = obj->begin(), end = obj->end(); i != end; ++i)
			if ( *i != 0 )
				(*i)->apply( this );
	}

	void Splitter::Inserter::visited(Names *obj)
	{
		for (Array::Iterator i = obj->begin(), end = obj->end(); i != end; ++i)
			if ( *i != 0 )
				(*i)->apply( this );
	}

	void Splitter::Inserter::visited(Dictionary *obj)
	{
		for (Dictionary::Iterator i = obj->begin(), end = obj->end(); i != end; ++i)
			if ( i->first != "Parent" && i->second != 0 )
				i->second->apply( this );
	}

	void Splitter::Inserter::visited(Reference *ref)
	{
		if ( document->find( ref->get() ) )
			return;

		Object::Ptr objectBody;
		{
			IndirectObject obj = splitter->getIndirectObject( ref );
			document->write( obj );
			objectBody = obj.object;
		}
		objectBody->apply( this );
	}
}